# Author:Li
import xadmin

from apps.courses.models import Course, Lesson, Video, CourseResource, CourseTag


class GlobalSettings(object):
    """xadmin 全局样式 左上角标题和底部公司名"""
    site_title = "在线课程平台后台管理系统"
    site_footer = "在线课程平台"
    # menu_style = "accordion"  # 左侧列表折叠布局


class BaseSettings(object):
    # 增加皮肤选择
    enable_themes = True
    use_bootswatch = True


class CourseAdmin(object):
    list_display = ["name", "desc", "detail", "degree", "learn_times", "students"]
    # 配置显示字段
    search_fields = ["name", "desc", "detail", "degree", "students"]
    # 配置搜索字段
    list_filter = ["name", "teacher__name", "desc", "detail", "degree", "learn_times", "students"]
    # 过滤器
    list_editable = ["desc", "degree"]
    # 列表页直接修改


class LessonAdmin(object):
    list_display = ["course", "name", "add_time"]
    # 配置显示字段
    search_fields = ["course", "name"]
    # 配置搜索字段
    list_filter = ["course__name", "name", "add_time"]
    # 过滤器 course__name,在外键的某个字段上进行过滤


class VideoAdmin(object):
    list_display = ["lesson", "name", "add_time"]
    # 配置显示字段
    search_fields = ["lesson", "name"]
    # 配置搜索字段
    list_filter = ["lesson", "name", "add_time"]
    # 过滤器


class CourseResourceAdmin(object):
    list_display = ["course", "name", "file", "add_time"]
    # 配置显示字段
    search_fields = ["course", "name", "file"]
    # 配置搜索字段
    list_filter = ["course", "name", "file", "add_time"]
    # 过滤器


class CourseTagAdmin(object):
    list_display = ["course", "tag", "add_time"]
    # 配置显示字段
    search_fields = ["course", "tag"]
    # 配置搜索字段
    list_filter = ["course", "tag", "add_time"]
    # 过滤器


xadmin.site.register(Course, CourseAdmin)
xadmin.site.register(Lesson, LessonAdmin)
xadmin.site.register(Video, VideoAdmin)
xadmin.site.register(CourseResource, CourseResourceAdmin)
xadmin.site.register(CourseTag, CourseTagAdmin)
# 将模型注册

xadmin.site.register(xadmin.views.CommAdminView, GlobalSettings)
xadmin.site.register(xadmin.views.BaseAdminView, BaseSettings)
#  注册xadmin全局样式
